package com.mrkun.vueshop.controller;

import com.github.pagehelper.PageInfo;
import com.mrkun.vueshop.DTO.FundInfoChartDTO;
import com.mrkun.vueshop.DTO.FundInfoDTO;
import com.mrkun.vueshop.mapper.FundInfoMapper;
import com.mrkun.vueshop.model.FundInfo;
import com.mrkun.vueshop.service.FundInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author by yong
 * @date 2020/3/21
 */
@RestController
public class FundInfoController {

    @Autowired
    private FundInfoMapper fundInfoMapper;

    @Autowired
    private FundInfoService fundInfoService;

    @GetMapping("/fund_info/get_all/{date}/{page}/{size}/{fundType}")
    public PageInfo<FundInfoDTO> getAll(@PathVariable("date")String date,
                                        @PathVariable("page")Integer page,
                                        @PathVariable("size")Integer size,
                                        @PathVariable("fundType")String fundType,
                                        @RequestParam("query")String query){
        if (fundType.equals("all")){
            fundType = null;
        }
        return fundInfoService.findFundInfoList(page,size,date,fundType,"%"+query.trim()+"%");
    }

    @GetMapping("/fund_info/getChange/{fundId}")
    public List<FundInfoChartDTO> getChart(@PathVariable("fundId")Integer fundId){
        return  fundInfoMapper.findChartData(fundId);
    }
}
